package com.distortiongames.level27.generation
{
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class Direction
	{
		public static const NORTH:int = 0, SOUTH:int = 1, EAST:int = 2, WEST:int = 3;
		private var _direction:int;
		
		public function get direction():int
		{
			return _direction;
		}
		
		public function set direction(value:int):void
		{
			_direction = value;
		}
		
		public function Direction(direction:int)
		{
			this._direction = direction;
		}
		
		public function copy():Direction
		{
			return new Direction(this.direction);
		}
		
		public function clockwise():void
		{
			switch (_direction)
			{
				case NORTH: 
					direction = EAST;
					break;
				case EAST: 
					direction = SOUTH;
					break;
				case SOUTH: 
					direction = WEST;
					break;
				case WEST: 
					direction = NORTH;
					break;
			}
		}
		
		public function counterClockwise():void
		{
			switch (direction)
			{
				case NORTH: 
					direction = WEST;
					break;
				case WEST: 
					direction = SOUTH;
					break;
				case SOUTH: 
					direction = EAST;
					break;
				case EAST: 
					direction = NORTH;
					break;
			}
		}
		
		public function flip():void
		{
			switch (direction)
			{
				case NORTH: 
					direction = SOUTH;
					break;
				case WEST: 
					direction = EAST;
					break;
				case SOUTH: 
					direction = NORTH;
					break;
				case EAST: 
					direction = WEST;
					break;
			}
		}
		
		public function toPoint():Point
		{
			var tempPoint:Point = null;
			switch (direction)
			{
				case NORTH: 
					tempPoint = new Point(0, -1);
					break;
				case EAST: 
					tempPoint = new Point(1, 0);
					break;
				case SOUTH: 
					tempPoint = new Point(0, 1);
					break;
				case WEST: 
					tempPoint = new Point(-1, 0);
					break;
			}
			return tempPoint;
		}
		
		public function getOtherDirections():Vector.<Direction>
		{
			var otherDirections:Vector.<Direction> = new Vector.<Direction>;
			switch (direction)
			{
				case NORTH: 
					otherDirections[0] = new Direction(EAST);
					otherDirections[1] = new Direction(SOUTH);
					otherDirections[2] = new Direction(WEST);
					break;
				case EAST: 
					otherDirections[0] = new Direction(NORTH);
					otherDirections[1] = new Direction(SOUTH);
					otherDirections[2] = new Direction(WEST);
					break;
				case WEST: 
					otherDirections[0] = new Direction(EAST);
					otherDirections[1] = new Direction(SOUTH);
					otherDirections[2] = new Direction(NORTH);
					break;
				case SOUTH: 
					otherDirections[0] = new Direction(EAST);
					otherDirections[1] = new Direction(NORTH);
					otherDirections[2] = new Direction(WEST);
					break;
			}
			return otherDirections;
		}
		
		public function getLeftAndRight():Vector.<Direction>
		{
			var otherDirections:Vector.<Direction> = new Vector.<Direction>;
			switch (direction)
			{
				case NORTH: 
					otherDirections[0] = new Direction(EAST);
					otherDirections[1] = new Direction(WEST);
					break;
				case EAST: 
					otherDirections[0] = new Direction(NORTH);
					otherDirections[1] = new Direction(SOUTH);
					break;
				case WEST: 
					otherDirections[0] = new Direction(SOUTH);
					otherDirections[1] = new Direction(NORTH);
					break;
				case SOUTH: 
					otherDirections[0] = new Direction(WEST);
					otherDirections[1] = new Direction(EAST);
					break;
			}
			return otherDirections;
		}
		
		public static function getRandomDirection():Direction
		{
			var random:int = Generator.random.nextInt(3);
			var direction:Direction = null;
			switch (random)
			{
				case 0: 
					direction = new Direction(NORTH);
					break;
				case 1: 
					direction = new Direction(EAST);
					break;
				case 2: 
					direction = new Direction(SOUTH);
					break;
				case 3: 
					direction = new Direction(WEST);
					break;
			}
			return direction;
		}
		
		public function toString() : String {
			var string:String = "";
			switch (direction)
			{
				case NORTH: 
					string = "North";
					break;
				case EAST: 
					string = "East";
					break;
				case WEST: 
					string = "West";
					break;
				case SOUTH: 
					string = "South";
					break;
			}
			return string;
		}
	}

}